package com.gujia.service;

import com.gujia.dao.CommentDao;
import com.gujia.model.Comment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.util.HtmlUtils;

import java.util.List;

/**
 * Created by GuJia on 2017/6/30.
 */
@Service
public class CommentService {

    @Autowired
    private CommentDao commentDao;

    @Autowired
    private SensitiveService sensitiveService;


    public List<Comment> selectByEntity(int entityId,String entityType){
            return  commentDao.selectByEntity(entityId,entityType);
    }

    public int addComment(Comment comment){
        comment.setContent(HtmlUtils.htmlEscape(comment.getContent()));
        comment.setContent(sensitiveService.filter(comment.getContent()));
        return commentDao.addComment(comment);
    }

    public int getCommentCount(int entityId,String entityType){
        return commentDao.getCommentCount(entityId,entityType);
    }

    public int getUserCommentCount(int userId) {
        return commentDao.getUserCommentCount(userId);
    }


    public void deleteComment(int id){
        commentDao.updateSatus(id,"1");
    }

    public Comment getCommentById(int id){
        return commentDao.getCommentById(id);
    }
}
